package freespiritsocial.io.user.viewmodel

import androidx.lifecycle.asLiveData
import androidx.lifecycle.viewModelScope
import freespiritsocial.io.user.data.model.bean.UserInfo
import freespiritsocial.io.user.data.model.bean.UserInfo.Companion.STATUS_DEL
import freespiritsocial.io.user.network.apiService
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.launch
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel
import me.hgj.jetpackmvvm.callback.livedata.StringLiveData
import me.hgj.jetpackmvvm.ext.request
import me.hgj.jetpackmvvm.ext.util.loge

class GetMyFollowsViewModel: BaseViewModel() {
    private val _followResult = MutableSharedFlow<UserInfo>(Int.MAX_VALUE)
    val resultFollow: SharedFlow<UserInfo> = _followResult


    //获取关注列表
    fun getFollowList() {
        request({
            _followResult.resetReplayCache()
            apiService.getFollowingList()
        },{
            viewModelScope.launch {
                _followResult.emitAll(it.asFlow())
            }
        })
    }

    fun getPeopleInfo(id: String) {
        request({
            apiService.getUserInfo(id)
        },{
            viewModelScope.launch {
                _followResult.emit(it)
            }
        })
    }

    fun removePeople(userInfo: UserInfo) {
        viewModelScope.launch {
            _followResult.emit(userInfo.also { it.eventStatus = STATUS_DEL })
        }
    }
}